package com.sky.controller.admin;


import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.mapper.CategoryMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/admin/category")
@Api(tags = "菜品分类相关接口")
public class CategoryController {

    private final CategoryService categoryService;

    //新增菜品
    @PostMapping
    @ApiOperation("新增分类菜品")
    public Result saveCategory(@RequestBody CategoryDTO categoryDTO){
        categoryService.save(categoryDTO);
        return Result.success();
    }

    //菜品分页查询
    @GetMapping("/page")
    @ApiOperation("分页查询菜品分类")
    public Result<PageResult> query( CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("查询的菜品信息为：{}",categoryPageQueryDTO);
        PageResult pageResult = categoryService.query(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    //启用禁用分类
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用分类")
    public Result setOrStop(@PathVariable Integer status,Long id){
        categoryService.setOrStop(status,id);
        return Result.success();
    }

    //修改分类
    @PutMapping
    @ApiOperation("修改分类状态")
    public Result updateSort(@RequestBody CategoryDTO categoryDTO){
        categoryService.updateSort(categoryDTO);
        return Result.success();
    }

    //根据id删除菜品
    @DeleteMapping
    @ApiOperation("根据id删除菜品")
    public Result deleteById(Long id){
        categoryService.deleteById(id);
        return Result.success();
    }

    //根据类型查询分类
    //根据类型查询分类
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> queryByType(Integer type){
        List<Category> list = categoryService.queryByType(type);
        return Result.success(list);
    }

}
